package com.zhifa.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhifa.dao.SalaryitemDao;
import com.zhifa.dao.SalarystandardDao;
import com.zhifa.entity.Salaryitem;
import com.zhifa.entity.Salarystandard;

@Service("salarystandardService")
public class SalarystandardService {
	
	@Resource
	SalarystandardDao salarystandardDao;
	
	@Resource
	SalaryitemDao salaryitemDao;
	
	public Salarystandard findsalarysByid(Integer id){
		return	salarystandardDao.findsalarysByid(id);
	}
	
	public Salarystandard findsalarysByTimestamp(String timestamp){
		return salarystandardDao.findsalarysByTimestamp(timestamp);
	}
	
	public int addSalarystandard(Salarystandard salarystandard){
		return salarystandardDao.addSalarystandard(salarystandard);
	}

	public boolean addStandardAndItems(Salarystandard salarystandard,List<Salaryitem>list){
		int addSalarystandard = salarystandardDao.addSalarystandard(salarystandard);
		int addSalaryitem = salaryitemDao.addSalaryitem(list);
		if (addSalaryitem>0&&addSalarystandard>0) {
			return true;
		}
		return false;
	}
	
	public String getNameByTimestamp(String timestamp){
		return salarystandardDao.getNameByTimestamp(timestamp);
	}
	
	public List<Salarystandard> getAll(){
		return salarystandardDao.getAll();
	}
	
	public List<Salarystandard> getListByMap(Map<String, Object>map){
		return salarystandardDao.getListByMap(map);
	}
	
	public Long getCountByMap(Map<String, Object>map){
		return salarystandardDao.getCountByMap(map);
	}
	
	public int updateSalarystandard(Salarystandard salarystandard,List<Salaryitem>list){
		int updateSalarystandard = salarystandardDao.updateSalarystandard(salarystandard);
		if (updateSalarystandard>0) {
			Integer deletesalarysByTimestamp = salaryitemDao.deletesalarysByTimestamp(salarystandard.getTimestamp());
			if (deletesalarysByTimestamp>0) {
				return salaryitemDao.addSalaryitem(list);
			}
		}
		return 0;
	}
	
	public int setSalarystandard(String timestamp){
		return salarystandardDao.setSalarystandard(timestamp);
	}
	
	public String gettimestampByName(String name){
		return salarystandardDao.gettimestampByName(name);
	}
}
